package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

/**
 * @author 十一
 * @Description
 * @create 2020-11-14-15:49
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserDetailByUsername(String username) {
        //查询用户基本信息
        UserVO userVO = baseMapper.finsUserByUsername(username);
        //查询用户的所有角色信息
        Set<RoleVO> roleVOSet = baseMapper.findUserRolesByUserId(userVO.getId());
        //遍历角色集合查询角色对应的角色信息
        for (RoleVO roleVO : roleVOSet) {
            Set<Permission> permissionSet = baseMapper.findPermissionByRoleId(roleVO.getId());
            roleVO.setPermissionSet(permissionSet);
        }
        userVO.setRoles(roleVOSet);
        return userVO;
    }
}
